package com.tarena.dubbo.order.web.service;

import com.tarena.dubbo.order.web.pojo.Order;
import com.tarena.dubbo.stock.api.StockApi;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class OrderService {
    @DubboReference
    private StockApi stockApi;
    public void createOrder(Order order) {
        //打印stockApi名字
        log.info("stockApi:{}",stockApi.getClass().getName());
        //调用减库存
        boolean result = stockApi.reduceStock(order.getProductId(), order.getCount());
        log.info("订单调用减库存的结果是:{}",result);
        log.info("创建订单数据:{},创建订单成功",order);
    }
    //关闭订单
    public void closeOrder(Order order) {
        log.info("订单数据关闭:{},订单关闭成功",order);
        //调用返还库存
        boolean result = stockApi.returnStock(order.getOrderId(), order.getCount());
        log.info("订单返还减库存的结果是:{}",result);
        log.info("创建撤销订单数据:{},创建撤销订单成功",order);

    }
}
